package com.hmy.cornpestdet.controller;

import com.hmy.cornpestdet.service.FileUploadService;
import com.hmy.cornpestdet.utils.FileHelper;
import com.hmy.cornpestdet.utils.Result;
import com.hmy.cornpestdet.vo.ImageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;


@RestController
@RequestMapping("/file")
public class FileUploadController {
    @Autowired
    FileUploadService fileUploadService;


    @PostMapping("/upload")
    public Result upload(@RequestParam("files") MultipartFile[] files) throws IOException {
        List<String> fileNewNameList = FileHelper.saveFileListToDisk(files);
        //将文件的新名字返回前端
        return Result.Success("接受成功",fileNewNameList);
    }

    @PostMapping("/submit")
    public Result submit(@RequestBody List<ImageVo> imageVos){
        return fileUploadService.submit(imageVos);
    }

}
